//
//  HWTongYongSheZhiViewController.m
//  HWanGame
//
//  Created by 陈道斌 on 2020/10/27.
//  Copyright © 2020 Chendaobin. All rights reserved.
//

#import "HWTongYongSheZhiViewController.h"
#import "HWTongYongSheZhiTableViewCell.h"
#import <SDWebImage/SDImageCache.h>
#import "SDImageCache.h"



@interface HWTongYongSheZhiViewController ()<UITableViewDataSource,UITableViewDelegate>
@property(strong,nonatomic) UITableView *mainaTableVie;
@property(strong,nonatomic) NSArray *dataArr;
@end

@implementation HWTongYongSheZhiViewController

-(UITableView *)mainaTableVie {

    if  (_mainaTableVie == nil) {

        _mainaTableVie = [[UITableView alloc]initWithFrame:CGRectMake(0, 0, kScreenW, kScreenH) style:UITableViewStylePlain];
        _mainaTableVie.delegate = self;
        _mainaTableVie.dataSource = self;
        _mainaTableVie.separatorStyle = UITableViewCellSeparatorStyleNone;
        
        _mainaTableVie.backgroundColor = [UIColor whiteColor];
        _mainaTableVie.backgroundColor = RGB(247, 247, 247);
        
    }
    return   _mainaTableVie ;

}


- (void)viewDidLoad {
    [super viewDidLoad];
    // Do any additional setup after loading the view.
    [self navigationView];
    [self setupUI];

    
}


- (void)navigationView {
    
  //   self.navigationItem.title = @"通用设置";
    
    self.navigationItem.title
    = [HWjianzhiduiObject keylocalization:@"通用设置"];
    
    
   //   self.dataArr = @[@"接收活动消息",@"聊天消息通知栏提醒",@"接收领积分提醒",@"自动检查版本更新",@"省流量",@"清理缓存"];
    
    
    
    
     NSUInteger intg = [[SDImageCache sharedImageCache] totalDiskSize];
    

     NSString * currentVolum = [NSString stringWithFormat:@"%@",[self fileSizeWithInterge:intg]];



   //   self.dataArr = @[@"接收活动消息",@"聊天消息通知栏提醒",@"接收领积分提醒",@"自动检查版本更新",@"清理缓存清除缓存可以加快加载速度"];
    
    self.dataArr = @[[HWjianzhiduiObject keylocalization:@"接收活动消息"],[HWjianzhiduiObject keylocalization:@"聊天消息通知栏提醒"],[HWjianzhiduiObject keylocalization:@"接收领积分提醒"],[HWjianzhiduiObject keylocalization:@"自动检查版本更新"],[HWjianzhiduiObject keylocalization:@"清除缓存可以加快加载速度"]];
    
    
   //  self.dataArr = @[@"接收活动消息",@"聊天消息通知栏提醒",@"接收领积分提醒",@"清理缓存清除缓存可以加快加载速度"];
     
    
    
    
}



- (void)setupUI {
    
    self.view.backgroundColor = [UIColor redColor];
    [self.view addSubview:self.mainaTableVie];
}




- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView {
    
    
    return  1;
    
}


- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section {
    
    return  self.dataArr.count;
    
    
     
    
    
}
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {
    
    
    static NSString *cellID = @"cellID";
  
    HWTongYongSheZhiTableViewCell *cell  = [tableView dequeueReusableCellWithIdentifier:cellID];
    
    if (!cell) {
        cell =  [[NSBundle mainBundle] loadNibNamed:@"HWTongYongSheZhiTableViewCell" owner:nil options:nil].firstObject;
        
    }

    cell.selectionStyle  = UITableViewCellSelectionStyleNone;
    cell.biaotiNamaLabel.text =  self.dataArr[indexPath.row];
    
    cell.biaotiNamaLabel.textColor = RGB(68, 68, 68);
    
    
    
    if (indexPath.row == 4) {
        cell.zuobianleironLabel.hidden = NO;
        cell.xuanzhongSwitch.hidden = YES;
        
      //   cell.biaotiNamaLabel.attributedText = [WMUtil attributedStringWithText:@"清理缓存清除缓存可以加快加载速度" withRangText:@"清除缓存可以加快加载速度" withColor:RGB(136, 136, 136) withFont:[UIFont systemFontOfSize:12]];
        
        cell.biaotiNamaLabel.text =  self.dataArr[indexPath.row];
        
        
        
         NSUInteger intg = [[SDImageCache sharedImageCache] totalDiskSize];
         NSString * currentVolum = [NSString stringWithFormat:@"%@",[self fileSizeWithInterge:intg]];
        
        cell.zuobianleironLabel.text = [NSString stringWithFormat:@"%@",currentVolum];
        
        
        
        
    } else {
        
          cell.zuobianleironLabel.hidden = YES;
         cell.xuanzhongSwitch.hidden = NO;
        
    }
    
    
    
    return  cell;
    
}


- (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath {
    
    
    return  64;
    
    
}


- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath {
    
    
    if (indexPath.row == 0) {
         
    } else if (indexPath.row == 1) {
        
        
        
    } else if (indexPath.row == 4) {
        
        [[HWDataBaseManager defaultManger] dropTable];
        
              [[SDImageCache sharedImageCache] clearDiskOnCompletion:^{
                  
               
                  
                  [self.mainaTableVie reloadData];
                  
              }];
              
              [MBProgressHUD showError:@"清除缓存成功"];
        
        
        
        
    }
    
    
}



// 计算内存大小
- (NSString *)fileSizeWithInterge:(NSInteger)size{
    // 1k = 1024, 1m = 1024k
    if (size < 1024) {// 小于1k
        return [NSString stringWithFormat:@"%ldB",(long)size];
    }else if (size < 1024 * 1024){// 小于1m
        CGFloat aFloat = size/1024;
        return [NSString stringWithFormat:@"%.0fK",aFloat];
    }else if (size < 1024 * 1024 * 1024){// 小于1G
        CGFloat aFloat = size/(1024 * 1024);
        return [NSString stringWithFormat:@"%.1fM",aFloat];
    }else{
        CGFloat aFloat = size/(1024*1024*1024);
        return [NSString stringWithFormat:@"%.1fG",aFloat];
    }
}




 
@end
